package org.hehui.supervisorysystem.rcpcore;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.menus.IWorkbenchContribution;
import org.hehui.supervisorysystem.actions.ExitAction;
import org.hehui.supervisorysystem.actions.OpenSitoyUserManagerViewPartAction;
import org.hehui.supervisorysystem.actions.OpenSitoyComputerManagerViewPartAction;
import org.hehui.supervisorysystem.actions.RestartAction;
import org.hehui.supervisorysystem.actions.SystemUpdateAction;
import org.hehui.supervisorysystem.login.SaveLogInfo;
import org.hehui.supervisorysystem.ui.StatusBarContributionItem;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
	
	private Action systemUpdateAction, restartAction, exitAction;    

private Action openSUM_VP, openCM_VP;
private IWorkbenchAction welcomeAction, helpAction, openPreferencesAction, aboutSystemAction;

private StatusBarContributionItem statusBarContributionItem;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
	super(configurer);
}

protected void makeActions(IWorkbenchWindow window) {
	//Help Actions
	welcomeAction = ActionFactory.INTRO.create(window);
	welcomeAction.setText("Welcome");
	welcomeAction.setToolTipText("Welcome");
	register(welcomeAction);
	
	helpAction = ActionFactory.HELP_CONTENTS.create(window);
	helpAction.setText("Help");
	helpAction.setToolTipText("Help");
	register(helpAction);
	
	aboutSystemAction = ActionFactory.ABOUT.create(window);
	register(aboutSystemAction);

	
	//System Actions
	systemUpdateAction = new SystemUpdateAction();
	register(systemUpdateAction);
	
	restartAction = new RestartAction();
	register(restartAction);		
	
	exitAction = new ExitAction();
	register(exitAction);
	
	
	//Window Actions
	openSUM_VP = new OpenSitoyUserManagerViewPartAction();
	register(openSUM_VP);
	
	openCM_VP = new OpenSitoyComputerManagerViewPartAction();
	register(openCM_VP);
	
	openPreferencesAction = ActionFactory.PREFERENCES.create(window);
	register(openPreferencesAction);
		
	//生成状态栏信息
	String msg = "ID:" + SaveLogInfo.getInstance().getUsername();
	statusBarContributionItem = new StatusBarContributionItem(msg);
	statusBarContributionItem.setVisible(true);
	
}

protected void fillMenuBar(IMenuManager menuBar) {
	//System Menu
	MenuManager systemMenu = new MenuManager("&System","systemMenu");
	menuBar.add(systemMenu);
	systemMenu.add(systemUpdateAction);
	systemMenu.add(restartAction);
	systemMenu.add(exitAction);
	
	//Data Menu
	MenuManager dataMenu = new MenuManager("&Data","dataMenu");
	menuBar.add(dataMenu);
//	dataMenu.add(dataBackupAction);
//	dataMenu.add(dataRestoreAction);
	
	MenuManager windowMenu = new MenuManager("&Window",IWorkbenchActionConstants.M_WINDOW);
	menuBar.add(windowMenu);
	windowMenu.add(openCM_VP);
	windowMenu.add(openSUM_VP);
	windowMenu.add(new Separator());
	windowMenu.add(openPreferencesAction);
	
	MenuManager perspectiveMenu = new MenuManager("&Perspective",IWorkbenchActionConstants.M_FILE);
	perspectiveMenu.add(openCM_VP);
	menuBar.add(perspectiveMenu);
	
	// Help Menu
	MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
	menuBar.add(helpMenu);	
	helpMenu.add(welcomeAction);
	helpMenu.add(helpAction);
	helpMenu.add(aboutSystemAction);
	
}


@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
//	IToolBarManager systemToolBar = new ToolBarManager(SWT.FLAT|SWT.SHADOW_OUT);
//	coolBar.add(systemToolBar);
//	systemToolBar.add(systemUpdateAction);
//	systemToolBar.add(logOffAction);
	
	IToolBarManager viewPartToolBar = new ToolBarManager(SWT.FLAT|SWT.SHADOW_OUT);
	coolBar.add(viewPartToolBar);
	viewPartToolBar.add(openCM_VP);
	viewPartToolBar.add(openSUM_VP);

	

}


@Override
protected void fillStatusLine(IStatusLineManager statusLineManager) {
	statusLineManager.add(statusBarContributionItem);
}




}
